
using Youz.Common.DBUtility;
using Youz.CreditRepay.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace Youz.CreditRepay.DAL
{
    /// <summary>
    /// Sys_Version Data Class
    /// </summary>
    public partial class Sys_VersionDAL : BaseDAL
    {
		private DbHelperSQL DbHelperSQL = new DbHelperSQL();
        public string TableName = "Sys_Version";

        public Sys_VersionDAL()
        {}

        #region  成员方法
        /// <summary>
        ///  新增一条数据
        /// </summary>
        public bool Add(Sys_Version model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("insert into [Sys_Version](");
            strSql.Append("[VersionID],[VersionNo],[DeviceType],[Status],[IsForceUpdate],[Comment],[Creater],[CreateTime],[PackageType],[Package]");
            strSql.Append(") values (");
            strSql.Append("NEWID(),@VersionNo,@DeviceType,@Status,@IsForceUpdate,@Comment,@Creater,@CreateTime,@PackageType,@Package");
            strSql.Append(")");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@VersionNo", model.VersionNo),
                    new SqlParameter("@DeviceType", model.DeviceType),
                    new SqlParameter("@Status", model.Status),
                    new SqlParameter("@IsForceUpdate", model.IsForceUpdate),
                    new SqlParameter("@Comment", model.Comment),
                    new SqlParameter("@Creater", model.Creater),
                    new SqlParameter("@PackageType", model.PackageType),
                    new SqlParameter("@Package", model.Package),
                    new SqlParameter("@CreateTime", model.CreateTime)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        ///  保存一条数据
        /// </summary>
        public bool Update(Sys_Version model)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("update [Sys_Version] set ");
            strSql.Append("[VersionNo]=@VersionNo,[DeviceType]=@DeviceType,[Status]=@Status,[IsForceUpdate]=@IsForceUpdate,[Comment]=@Comment,[Creater]=@Creater,[CreateTime]=@CreateTime,[PackageType]=@PackageType,[Package]=@Package");
            strSql.Append(" where [VersionID]=@VersionID");
			
            SqlParameter[] parameters = {
                  
                    new SqlParameter("@VersionID", model.VersionID),
                    new SqlParameter("@VersionNo", model.VersionNo),
                    new SqlParameter("@DeviceType", model.DeviceType),
                    new SqlParameter("@Status", model.Status),
                    new SqlParameter("@IsForceUpdate", model.IsForceUpdate),
                    new SqlParameter("@Comment", model.Comment),
                    new SqlParameter("@Creater", model.Creater),
                    new SqlParameter("@PackageType", model.PackageType),
                    new SqlParameter("@Package", model.Package),
                    new SqlParameter("@CreateTime", model.CreateTime)
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        ///</summary>
        public bool Delete(Guid VersionID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from [Sys_Version] ");
            strSql.Append(" where [VersionID]=@VersionID");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("@VersionID", VersionID)             
              
            };

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Sys_Version Get(Guid VersionID)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select  top 1 * from [Sys_Version] ");
            strSql.Append(" where [VersionID]=@VersionID");
			
            SqlParameter[] parameters = {
			
                new SqlParameter("VersionID", VersionID)             
              
            };

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return Get(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

		/// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Sys_Version Get(DataRow row)
        {
            if (row == null) return null;

            Sys_Version model = new Sys_Version();
	
            
            if (row["VersionID"] != DBNull.Value)
            {
                model.VersionID = (Guid)row["VersionID"];
            }      
            
            if (row["VersionNo"] != DBNull.Value)
            {
                model.VersionNo = (String)row["VersionNo"];
            }      
            
            if (row["DeviceType"] != DBNull.Value)
            {
                model.DeviceType = (AppDeviceType)(Int32)row["DeviceType"];
            }      
            
            if (row["Status"] != DBNull.Value)
            {
                model.Status = (Int32)row["Status"];
            }      
            
            if (row["IsForceUpdate"] != DBNull.Value)
            {
                model.IsForceUpdate = (Int32)row["IsForceUpdate"];
            }      
            
            if (row["Comment"] != DBNull.Value)
            {
                model.Comment = (String)row["Comment"];
            }

            if (row["Package"] != DBNull.Value)
            {
                model.Package = (String)row["Package"];
            }

            if (row["PackageType"] != DBNull.Value)
            {
                model.PackageType = (AppPackageType)(int)row["PackageType"];
            } 
            
            if (row["Creater"] != DBNull.Value)
            {
                model.Creater = (String)row["Creater"];
            }      
            
            if (row["CreateTime"] != DBNull.Value)
            {
                model.CreateTime = (DateTime)row["CreateTime"];
            }      
            

            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Gets(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
			
            strSql.Append("select * from [Sys_Version] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet Gets(int Top, string sqlWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" *  FROM [Sys_Version] ");
			
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            if(filedOrder.Trim() != "")
            {
                strSql.Append(" order by " + filedOrder);
            }
			
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string sqlWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM [Sys_Version] ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 获得数据列表分页
        /// </summary>
        public DataTable Gets(string sqlWhere, int pageindex, int pagesize, out int total, params SqlParameter[] cmdParms)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(" SELECT * FROM [Sys_Version]  ");
            if (sqlWhere.Trim() != "")
            {
                strSql.Append(" where " + sqlWhere);
            }

            int count = 0;
            DataTable dt = DbHelperSQL.GetPager(pageindex, pagesize, "" + strSql + "", "order by createTime desc ", out count, cmdParms);
            total = count;
            return dt;
        }
      #endregion  成员方法
    }
}


  